var Router = function() {

	this.loaded = {};
	this.loadedContent = [];

	this.checkloaded = function(name) {
		if (this.loadedContent.exists(name)) {
			eval("this.loaded." + name.camelcase(1) + ".restart();");
			return;
		}
	};
	
	this.loadSmartphoneContent = function() {
		
		var name = "home-smartphone";
		
		this.checkloaded(name);
		
		LazyLoad.css('res/css/' + name + '.css');
		LazyLoad.js(
			['res/script/' + name + '.js'],
			function () {
				this.loadContent("layout-" + name, name, "/" + name + ".xml");
			},
			null,
			this
		);		
	};
	
	this.loadTabletContent = function() {

		window.location = "ipad/index.xml";
		
//		var name = "home-tablet";		
//		this.checkloaded(name);
//		
//		LazyLoad.css(['res/css/' + name + '.css','ipad/res/css/basket.css','ipad/res/css/mediaquerie.css','ipad/res/css/reset.css','ipad/res/css/sapient.css']);
//		LazyLoad.js(
//			['ipad/res/script/jquery-1.7.2-min.js','ipad/res/script/basketDB.js','ipad/res/script/iscroll.js','ipad/res/script/fashiongrid.js','ipad/res/script/sapient.js','res/script/' + name + '.js'],
//			function () {
//				this.loadContent("root", name, "/ipad/index.xml");
//			},
//			null,
//			this
//		);			
	};
	
	this.loadContent = function(layoutname, classname, pageurl) {
		var loader = new tactile.ContentLoader();
		loader.onsuccess.subscribe(( function(e) {
				var newcomponents = e.loader.getComponents();
				document.getElementById("contentloader-target").appendChild(tactile.page.getComponent(layoutname).elem);					
				eval("this.loaded." + classname.camelcase(1) + " = new " + classname.camelcase() + "; this.loaded." + classname.camelcase(1) + ".init();");
				tactile.foundation.LayoutManager.updateLayout();
				this.loadedContent.push(classname);
		}).bind(this));
		loader.onerror.subscribe(function(e) {
			console.log(e.message);
		});
		loader.load({
			url :  pageurl
		});
	};	


}